<?php
/**
 * Created by PhpStorm.
 * User: s.utkin
 * Date: 03.09.14
 * Time: 17:34
 */

namespace Messenger\Users;


use Messenger\Groups;
use Messenger\BaseAction;

class UnreadMessagesCountAction extends BaseAction
{
	protected static $isPublic = true;
	
	/**
	 * Выводит количество непрочтенных сообщений в группе
	 */
	protected function run()
	{
		$groupId = $this->request->groupId;
		$targetProfileId = $this->request->targetProfileId;

		if (empty($targetProfileId)) {
			throw new \Exception('Id профиля пуст', 404);
		}

		/** @var Groups $groupModel */
		$groupModel = Groups::find($groupId);

		$this->response->unseenMessagesCount = $groupModel->unseenMessages[$targetProfileId]->count;
	}
}